<!DOCTYPE html>
<html>
<head>
    <title>region form</title>
    <#include "/header.html">
</head>
<body class="bg-white">
<div id="appMain">
    <form class="layui-form layuimini-form" action="" lay-filter="dataForm">
        <div class="layui-form-item">
            <label class="layui-form-label">会员</label>
            <div class="layui-input-block">
                <select id="jobVipId" name="jobVipId" lay-search>
      			</select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">初始发布次数</label>
            <div class="layui-input-block">
                <input type="text" name="initPublish" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">剩余发布次数</label>
            <div class="layui-input-block">
                <input type="text" name="publish" value="" class="layui-input">
            </div>
        </div>
       
        <div class="layui-form-item">
            <label class="layui-form-label">初始刷新置顶次数</label>
            <div class="layui-input-block">
                <input type="text" name="initRedoTop" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">置顶时长（天）</label>
            <div class="layui-input-block">
                <input type="text" name="topTime" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">剩余刷新置顶次数</label>
            <div class="layui-input-block">
                <input type="text" name="redoTop" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">初始置顶次数</label>
            <div class="layui-input-block">
                <input type="text" name="initTop" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">剩余置顶次数</label>
            <div class="layui-input-block">
                <input type="text" name="top" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">热点展示</label>
            <div class="layui-input-block">
                <input type="radio" name="hot" value="0" title="否">
                <input type="radio" name="hot" value="1" title="是">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">优先展示</label>
            <div class="layui-input-block">
                <input type="radio" name="priority" value="0" title="否">
                <input type="radio" name="priority" value="1" title="是">
            </div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">会员到期时间</label>
            <div class="layui-input-block">
                <input type="text" name="endTime" id="date" lay-verify="required" lay-reqtext="请选择时间" placeholder="请选择时间" autocomplete="off" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="1" title="使用中">
                <input type="radio" name="status" value="2" title="已过期" checked="">
                <input type="radio" name="status" value="3" title="禁用">
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" id="commitBtn" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    layui.use(['form', 'laydate', 'dtree', 'laytpl'], function () {
        var form = layui.form,
	        dtree = layui.dtree,
	        laytpl = layui.laytpl,
            $ = layui.$;
        var laydate = layui.laydate;
        var keywords = [];

        var _parent = parent;
        /* dtree.render({
            elem: "#menuTree",
            data: _parent.menuTreeData,
            icon: "-1",
            selectInputName: {
                nodeId: "parentId",
                context: "parentName"
            },
            // initLevel: 3,
            select: true, //指定下拉树模式
            done: function(res, $ul, first){
                if(first && _parent.formDataId > 0) {
                    $.ajax({
                        type: "POST",
                        url: serverUrl('app/job/info/' + _parent.formDataId),
                        success: function (result) {
                            if (result.code === 0) {
                                form.val('dataForm', result.info);
                                dtree.dataInit("menuTree", result.info.parentId);
                                dtree.selectVal("menuTree");
                                $('#uploadPreview').attr('src', result.info.image); //url
                                form.render();

                                $(result.info.keyword).each(function (i, v) {
                                    keywords.push(v);
                                });

                                laytpl($("#tagsTpl").html()).render(keywords, function(html){
                                    $("#keywords").html(html);
                                });
                                tag.render();
                                tag.on('add(keywords)', function (data) {
                                    keywords.push($(data.othis).text());
                                    console.log(keywords);
                                });
                                tag.on('delete(keywords)', function (data) {
                                    keywords.splice(data.index, 1);
                                    console.log(keywords);
                                });
                            }
                        }
                    });
                }
            }
        }); */
        
        //获取select
    	  $.ajax({
    			url:serverUrl("vipjob/nameall"),
    			type:"post",
    			dataType:"",
    			success:function(btn){
    		          var select = $("#jobVipId");
    			      	for (var j = 0; j < btn.count; j++) {
    				      	  select.append("<option value='"+btn.data[j].id+"'>"+btn.data[j].name+"</option>");
    			  		}
    		          layui.form.render("select");
    			},
    			error:function(){
    				console.log("获取失败");
    			}
    		})     
        laydate.render({
            elem: '#date',
            type: 'datetime'
          });
        $(document).ready(function () {
            if (parent.formDataId > 0) {
                $.ajax({
                    type: "POST",
                    url: serverUrl('user/jobvip/info/' + parent.formDataId),
                    data: {},
                    dataType: "json",
                    success: function (result) {
                        if (result.code === 0) {
                            form.val('dataForm', result.info);
                        }
                    }
                });
            }
        });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            /*alert(JSON.stringify(data.field));
            return false;*/
            var params = data.field;
            params['id'] = _parent.formDataId || null;
            params['label'] = keywords;
            
            var method = _parent.formDataId > 0 ? 'update' : 'save';
            submitFormData('user/jobvip/'+method, params, function (res) {
                
            });
            return false;
        });

    });
</script>
</body>
</html>